<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style> 
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {
    SelectImageRadio: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImageRadio()),
  },
  data() {
    return {
      appWindow: window,
      // 添加
      form: {
        mobile: "",
        realName: "",
        roleName: "",
        roleId: "",
        icon: "",
        password: "",
      },
      // 页面接口地址
      apiUrl: {
        create: "mall-site-portal/platform-admin/create",
        update: "mall-site-portal/platform-admin/update",
        detail: "mall-site-portal/platform-admin/getItem",
      },
      listCanAuthRole: [],

      // 是否查询到手机号
      show: "",
      // 查到用户的展示信息
      showData: {},

      // 图片路径
      imageUrl: "",

      mixinEdit_loading: false,
    };
  },
  methods: {
    // 初始化
    async init() {
      this.show = "";

      await this.mixinEdit_editBoxInit({
        model: "form",
        id: this.id,
        onInit: async () => {
          if (this.mixinEdit_editType == "update") {
            this.getUserInformation();
          }

          return true;
        },
      });
    },

    // 获取用户信息
    async getUserInformation() {
      // 获取用户信息
      let _data = await this.$vFN.Http.post(
        {
          url: "mall-site-portal/platform-admin/listCanAuthRole",
        },
        window
      );

      if (_data._ok) {
        this.listCanAuthRole = _data.data;
        console.log("7788", this.listCanAuthRole);
      }
    },

    // 修改提交参数
    mixinEdit_editFormSubmitExtend(data_) {
      if (this.show == 0) {
        data_.icon = data_.icon[0];
      } else {
        data_.icon = "";
      }

      return data_;
    },

    //  搜索按钮
    phoneInquiry(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.gaininquire();
        }
      });
    },

    // 手机号码查询
    async gaininquire() {
      this.mixinEdit_loading = true;

      let _data = await this.$vFN.Http.post(
        {
          url: "mall-site-portal/platform-admin/getAdminByMobile",
          data: {
            mobile: this.form.mobile,
          },
        },
        window
      );

      if (_data._ok) {
        // console.log("查询结果", !this.$vFN.Utils.isEmpty(_data.data));
        this.mixinEdit_loading = false;
        if (!this.$vFN.Utils.isEmpty(_data.data)) {
          this.$confirm("用户已存在，前往修改权限", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            this.getUserInformation();
            this.show = 1;
            this.showData = _data.data;
          });
        } else {
          this.$confirm("用户不存在，前往创建", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            this.getUserInformation();
            this.show = 0;
          });
        }
      }
    },

    // 头像选择
    validate(e) {
      return this.mixinEdit_formValidate("editForm");
    },

    // 选择角色
    selectRole(id) {
      this.form.roleId = id;
    },

    // 重置按钮
    resetButton() {
      this.show = "";
   
      this.form = {
        mobile: this.form.mobile,
        realName: "",
        roleName: "",
        roleId: "",
        icon: [],
        password: "",
      }
      
    },

  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>
